
package org.reliablesource.prism.gef.editor.parts;

import org.eclipse.draw2d.geometry.Rectangle;
import org.eclipse.gef.tools.CellEditorLocator;
import org.eclipse.jface.viewers.CellEditor;
import org.eclipse.swt.widgets.Text;
import org.reliablesource.prism.gef.editor.figures.StickyNoteFigure;

/**
 * 
 * StickyNoteCellEditorLocator.java 
 * 
 * Copyright (c) 2006, Reliable Source, Inc. All Rights Reserved
 * 
 * Created on: Apr 12, 2006
 * 
 * @author Dennis Park <a
 *         href="mailto:dennis.park@gmail.com">dennis.park@gmail.com</a>
 * 
 */
final public class StickyNoteCellEditorLocator implements CellEditorLocator {

	private StickyNoteFigure stickyNote;

	public StickyNoteCellEditorLocator(StickyNoteFigure stickyNote) {
		setLabel(stickyNote);
	}

	public void relocate(final CellEditor celleditor) {
		Text text = (Text) celleditor.getControl();
		Rectangle rect = stickyNote.getClientArea();
		stickyNote.translateToAbsolute(rect);
		org.eclipse.swt.graphics.Rectangle trim = text.computeTrim(0, 0, 0, 0);
		rect.translate(trim.x, trim.y);
		rect.width += trim.width;
		rect.height += trim.height;
		text.setBounds(rect.x, rect.y, rect.width, rect.height);
	}

	/**
	 * Returns the stickyNote figure.
	 */
	protected StickyNoteFigure getLabel() {
		return stickyNote;
	}

	/**
	 * Sets the Sticky note figure.
	 * 
	 * @param stickyNote
	 *            The stickyNote to set
	 */
	protected void setLabel(final StickyNoteFigure _stickyNote) {
		this.stickyNote = _stickyNote;
	}

}